<?php
if($_GET['order']){
    require '../config/config.php';
	session_start();
    $bnoRs=mysqli_fetch_array(mysqli_query($con,"select * from orderRecord where bno='".$_GET['order']."'"));
	if($bnoRs['user']!=$_SESSION['member']){
	    echo "<script>alert('系统异常！');location='./index.php;</script>";    
	}
    function request_post($url = '', $post_data = array())
    {
        if (empty($url) || empty($post_data)) {
            return false;
        }
        $o = "";
        foreach ($post_data as $k => $v) {
            $o .= "$k=" . urlencode($v) . "&";
        }
        $post_data = substr($o, 0, -1);
        $postUrl = $url;
        $curlPost = $post_data;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $postUrl);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    $url = ''; //官方支付网关，用于官方系统订单生成，请勿修改！暂不对外提供给服务！
    $post_data['AppId'] = ''; //请输入你的AppId
    $post_data['AppKey'] = ''; //请输入你的AppKey
    $post_data['out_trade_no'] = $bnoRs['bno']; //请输入商家订单号，也就是你系统的订单号。
    $post_data['subject'] = $bnoRs['subject']; //请输入订单名称
    $post_data['total_amount']  = $bnoRs['total_amount']; //请输入订单金额
    $res = request_post($url, $post_data);
    if ($res != "") {
        //var_dump($res);
        $res = substr($res, 27); //截取返回订单号，如果订单号出现异常，请调整此处！默认值为：27
        $payGateway = ""; //官方支付网关，用于进行支付处理，请勿修改！暂无对外提供服务！
        //echo "<br /><a href='" . $payGateway . "?orderNo=" . $res . "'>立即支付</a>";
        echo "<script>location='" . $payGateway . "?orderNo=" . $res . "';</script>";
    } else {
        echo "系统异常，暂时无法继续完成支付！";
    }
}else{
    echo "<script>alert('系统异常！');location='./order.php?order=".$_GET['order']."';</script>";
}